package com.house.Reborn.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

import java.util.*;
import java.util.Calendar;

public class Test {

    public static String JOB_NAME = "动态任务调度";
    public static String TRIGGER_NAME = "动态任务触发器";
    public static String JOB_GROUP_NAME = "XLXXCC_JOB_GROUP";
    public static String TRIGGER_GROUP_NAME = "XLXXCC_JOB_GROUP";

    public static void main(String[] args) throws SchedulerException {
        // create jobDetail
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity("myJob1", "myJobGroup1").build();
        //create Trigger
//        TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
//        triggerBuilder.withIdentity("myTrigger1","myTriggerGroup1");
//        triggerBuilder.startNow();
//        triggerBuilder.startAt(new Date());
//        Trigger trigger = triggerBuilder.build();
//        Calendar c = Calendar.getInstance();
//        c.setTimeInMillis(System.currentTimeMillis() + 3000*1L);
//        trigger.getTriggerBuilder().endAt(c.getTime());
//        trigger.getTriggerBuilder().forJob(jobDetail);
//        trigger.getTriggerBuilder().withDescription("我的触发器1");
        CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("myTrigger1","myTriggerGroup1")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/20 * * * * ?")).build();
        //设置重复执行次数
        //trigger.getTriggerBuilder().

        SchedulerFactory sf = new StdSchedulerFactory();
        Scheduler scheduler = null;
        try {
            scheduler = sf.getScheduler();
            scheduler.scheduleJob(jobDetail, trigger);
            //4、并执行启动、关闭等操作
            scheduler.start();

        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

}